package cn.zz.veggie.application.packer;

import java.util.Optional;

import cn.zz.veggie.web.types.vo.mgmt.MgmtProductQuoteVo;
import cn.zz.veggie.web.types.vo.mgmt.MgmtQuoteVo;
import cn.zz.veggie.model.domain.Product;
import cn.zz.veggie.model.domain.Quote;
import cn.zz.veggie.model.domain.User;

/**
 * @author zhongq
 * @since 2024/5/22
 */
public class UserQuotePacker {

	public static MgmtQuoteVo toMgmtUserQuoteVo(Quote quote, Product product, User user) {
		MgmtQuoteVo vo = new MgmtQuoteVo();
		vo.setId(quote.getId());
		vo.setPrice(quote.getPrice());
		vo.setCreatedAt(quote.getCreatedAt());
		vo.setUpdatedAt(quote.getUpdatedAt());
		vo.setProduct(ProductPacker.toHisProductVo(product));
		vo.setUser(UserPacker.toHisUserVo(user));

		return vo;
	}

	public static MgmtProductQuoteVo toMgmtProdQuoteVo(Product p, Integer quote) {
		final MgmtProductQuoteVo vo = new MgmtProductQuoteVo();
		vo.setProduct(ProductPacker.toHisProductVo(p));
		vo.setQuote(Optional.ofNullable(quote).orElse(p.getPrice()));
		return vo;
	}
}